package cn.zwx.learn.mybatis.example.croe.binding;

import cn.zwx.learn.mybatis.example.croe.session.DefaultSqlSession;
import lombok.AllArgsConstructor;

import java.lang.reflect.Proxy;

/**
 * mapperProxy工厂类
 * @author zhangwenxue 
 * @date 2022/5/7 22:35
*/
@AllArgsConstructor
public class MapperProxyFactory<T> {
    private Class<T> mapperInterface;
    private Class object;

    /**
     * 创建代理对象
     */

    public T newInstance(DefaultSqlSession sqlSession) {
        return (T) Proxy.newProxyInstance(mapperInterface.getClassLoader(), new Class[] { mapperInterface }, new MapperProxy(sqlSession, object));
    }
}
